import time


# 方法1: 使用异常处理流程控制（不推荐）
def with_exceptions(n):
    results = []
    for i in range(n):
        try:
            if i % 2 == 0:
                raise ValueError("测试异常")
            results.append(i)
        except ValueError:
            pass
    return results


# 方法2: 使用条件判断（推荐）
def without_exceptions(n):
    results = []
    for i in range(n):
        if i % 2 != 0:
            results.append(i)
    return results


n = 10000

start = time.time()
with_exceptions(n)
exception_time = time.time() - start

start = time.time()
without_exceptions(n)
normal_time = time.time() - start

print(f"使用异常: {exception_time:.6f}秒")
print(f"使用条件: {normal_time:.6f}秒")
print(f"性能差异: {exception_time/normal_time:.2f}倍")
